package jk.framework.canary.core.po;

import java.util.*;

/**
 * @author cuichao
 * 路由上下文
 */
public class RouteContext<T> {

    /**
     * 路由key
     */
    private String routeKey;

    /**
     * 当前版本
     */
    private String currentVersion;

    /**
     * 主要判断条件
     */
    protected T condition;

    /**
     * 上下文标签
     */
    protected Map<String, Collection<String>> labels;


    public String getRouteKey() {
        return routeKey;
    }



    public String getCurrentVersion() {
        return currentVersion;
    }

    public T getCondition() {
        return condition;
    }



    public Collection<String> getLabels(String key){
        if(this.labels == null || this.labels.isEmpty()){
            return null;
        }
        return this.labels.get(key);

    }



    public RouteContext<T> setRouteKey(String routeKey) {
        this.routeKey = routeKey;
        return this;
    }


    public RouteContext<T> setCurrentVersion(String currentVersion) {
        this.currentVersion = currentVersion;
        return this;
    }


    public RouteContext<T> setCondition(T condition) {
        this.condition = condition;
        return this;
    }


    public RouteContext<T> setLabels(String key, Collection<String> values){
        if(this.labels == null){
            this.labels = new HashMap<>(16);
        }
        this.labels.put(key,values);
        return this;
    }


    public Set<String> getLabelsKeys(){
        if(this.labels == null){
            this.labels = new HashMap<>(16);
        }
        return this.labels.keySet();
    }



}
